package impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Keevu
 * Date: 17/08/11
 * Time: 15:26
 * To change this template use File | Settings | File Templates.
 */
public class InsertionSorter extends AbstractSorter{


    public InsertionSorter() {
        super(SorterType.INSERTION);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        for (int i = 0; i < ts.size(); i++) {
            for (int j = i; j > 0; j--) {
                if (!greater(tComparator,ts,j,j -1)) {
                    swap(ts, j, j - 1);
                } else {
                    break;
                }
            }
        }
    }


}
